package com.net.xpay.backend.scheduler;


import com.beust.jcommander.internal.Lists;
import com.net.xpay.common.enums.user.SecurityStatus;
import com.net.xpay.common.manager.UserManager;
import com.net.xpay.common.model.search.UserSearchModel;
import com.net.xpay.common.service.UserFrozenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 冻结长期不活跃的用户
 */
@Slf4j
@Component
public class FrozenUserScheduler {

    @Autowired
    private UserManager userManager;

    @Autowired
    private UserFrozenService userFrozenService;

    List<Long> whiteUserIds = Lists.newArrayList(10000L, 10002L);

    @Scheduled(cron = "0 0 4 * * *")
    public void frozenUser() {
        log.info("frozenUser start");
        UserSearchModel searchModel = new UserSearchModel();
        searchModel.setSecurityStatus(SecurityStatus.NORMAL);
        List<Long> userIds = userManager.listIds(searchModel);
        for (Long userId : userIds) {
            if (whiteUserIds.contains(userId)) {
                continue;
            }
            userFrozenService.checkFrozenUser(userId);
        }

        log.info("frozenUser end");
    }


}
